package core

import "strings"

func ParseReplaceSet(s string) [][2]string {
	return parseReplaceSetWithSymbol(s, "→")
}

func ParseReplaceSets(sets []string) [][][2]string {
	ret := [][][2]string{}
	for _, s := range sets {
		ret = append(ret, ParseReplaceSet(s))
	}
	return ret
}

func parseReplaceSetWithSymbol(s string, symbol string) [][2]string {
	lines := strings.Split(s, "\n")
	ret := [][2]string{}
	for _, l := range lines {
		if strings.Contains(l, "//") {
			continue
		}
		if strings.Contains(l, symbol) {
			split := strings.Split(strings.ReplaceAll(l, "\t", ""), symbol)

			if len(split) != 2 {
				panic("replace set invalid!")
			}
			ret = append(ret, [2]string{split[0], split[1]})
		}
	}

	return ret
}
